﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:s="clr-namespace:System;assembly=mscorlib"
                    xmlns:tc="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit">

    <ControlTemplate x:Key="busyIndicator"
                     TargetType="tc:BusyIndicator">
        <Grid>
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="VisibilityStates">
                    <VisualState x:Name="Hidden">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00"
                                                           Duration="00:00:00.001"
                                                           Storyboard.TargetProperty="(UIElement.Visibility)"
                                                           Storyboard.TargetName="busycontent">
                                <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Collapsed</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00"
                                                           Duration="00:00:00.001"
                                                           Storyboard.TargetProperty="(UIElement.Visibility)"
                                                           Storyboard.TargetName="overlay">
                                <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Collapsed</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Visible">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00"
                                                           Duration="00:00:00.001"
                                                           Storyboard.TargetProperty="(UIElement.Visibility)"
                                                           Storyboard.TargetName="busycontent">
                                <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Visible</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00"
                                                           Duration="00:00:00.001"
                                                           Storyboard.TargetProperty="(UIElement.Visibility)"
                                                           Storyboard.TargetName="overlay">
                                <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Visible</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
                <VisualStateGroup x:Name="BusyStatusStates">
                    <VisualState x:Name="Idle">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00"
                                                           Duration="00:00:00.001"
                                                           Storyboard.TargetProperty="(Control.IsEnabled)"
                                                           Storyboard.TargetName="content">
                                <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                    <DiscreteObjectKeyFrame.Value>
                                        <s:Boolean>True</s:Boolean>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Busy">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00"
                                                           Duration="00:00:00.001"
                                                           Storyboard.TargetProperty="(Control.IsEnabled)"
                                                           Storyboard.TargetName="content">
                                <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                    <DiscreteObjectKeyFrame.Value>
                                        <s:Boolean>False</s:Boolean>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <ContentControl x:Name="content"
                            ContentTemplate="{TemplateBinding ContentTemplate}"
                            Content="{TemplateBinding Content}"
                            HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />
            <Rectangle x:Name="overlay"
                       Fill="Transparent"
                       Opacity="0" />
            <ContentPresenter x:Name="busycontent">
                <Grid HorizontalAlignment="Right"
                      VerticalAlignment="Top">
                    <StackPanel Orientation="Horizontal"
                                Margin="0 16 0 0">
                        <TextBlock Text="Loading"
                                   Foreground="White"
                                   Margin="0 0 4 0" />
                        <ProgressBar Width="75"
                                     Style="{TemplateBinding ProgressBarStyle}"
                                     Foreground="{StaticResource specialBrush}" />
                    </StackPanel>
                </Grid>
            </ContentPresenter>
        </Grid>
    </ControlTemplate>

</ResourceDictionary>